<template>
  <view class="container page-container">
    <CustomNav />
    <Home v-if="currentPage === 0" />
    <Exhibition v-else-if="currentPage == 1" />
    <Shop v-else-if="currentPage == 2" />
    <Account v-else="currentPage == 3" :currentTab="tabIndex" @change="changeAccountTab" />

    <Tabbar @change="changeTab" :currentPage="currentPage" />
  </view>
</template>

<script lang="ts" setup>
import { ref, reactive, getCurrentInstance, onMounted, watch } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'

import CustomNav from '@/components/custom-nav/custom-nav.vue'
import Tabbar from '@/components/tabbar/tabbar.vue'
import Home from './components/home/home.vue'
import Exhibition from './components/exhibition/exhibition.vue'
import Shop from './components/shop/shop.vue'
import Account from './components/account/account.vue'

let currentPage = ref<number>(0)
let tabIndex = ref<number>(0)
const changeTab = (index: number) => {
  console.log('首页获取传参', index)
  currentPage.value = index
}

const changeAccountTab = (index: number) => {
  tabIndex.value = index
  console.log('账户页获取tab改变传参', index)
}
onLoad((opt) => {
  if (opt && opt.params) {
    let params = JSON.parse(opt.params)
    if (params.index) {
      currentPage.value = params.index
    }
    if (params.tabIndex) {
      tabIndex.value = params.tabIndex
    }
  }
})
</script>

<style></style>
